﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using CanDoo;
using CanDoo.Core;
using CanDoo.Core.Data;
using CanDoo.Data;
using CanDoo.Extensions;
using CanDoo.Oil.Core.Contracts;
using CanDoo.Oil.Core.Models;

namespace CanDoo.Oil.Core.Services
{
    /// <summary>
    /// 业务实现——采购预付款
    /// </summary>
    public class BuyAdvanceMoneyService : CanDoo.Data.Entity.Services.ServiceBase<BuyAdvanceMoney>, IBuyAdvanceMoneyContract
    {
        public BuyAdvanceMoneyService()
        {
        
        }

        public string GetNewCode()
        {
            var startStr = "YFYFD";
            var dateStr = DateTime.Now.ToString("yyMMdd");
            var codePrefix = startStr + dateStr;

            //生成新单据号
            var newCode = "";
            var entity = Entities.Where(p => p.Code.StartsWith(codePrefix)).OrderByDescending(p => p.Code).FirstOrDefault();
            if (entity == null)
                newCode = codePrefix + "0001";
            else
                newCode = startStr + (int.Parse(entity.Code.Substring(startStr.Length)) + 1);
            return newCode;
        }
    }
}
